Fix ProcessRunner StringBuilder race condition causing assertion failure#124269
Fix ProcessRunner StringBuilder race condition causing assertion failure#124269
Conversation
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
|
@copilot please invoke the code-review skill and post your analysis/results as a comment on this PR |
There was a problem hiding this comment.
Pull request overview
This PR addresses a race condition in ProcessRunner’s stdout/stderr capture that can corrupt the shared StringBuilder and trigger StringBuilder.ExpandByABlock assertions during concurrent appends.
Changes:
- Adds synchronization around
_outputCapture.AppendLine(...)in both stdout and stderr event handlers. - Switches synchronization to lock on the
_outputCaptureinstance itself (instead of a separate lock object).
🤖 Copilot Code Review — PR #124225Holistic AssessmentMotivation: The bug is real — Approach: Adding Summary: ✅ LGTM. The fix is minimal, correct, and consistent with the existing file conventions. Detailed Findings✅ Thread-safety fix is correct and sufficientThe two event handlers ( ✅ No lock needed on
|
|
/ba-g DeadLetter on Apple TV, the rest are known |
Description
Closes #124067
ProcessRunner's stdout and stderr handlers concurrently appended to a shared
StringBuilderwithout synchronization, corrupting internal state and triggering assertion failureminBlockCharCount > 0inExpandByABlock.Changes
_outputCaptureStringBuilder in bothStandardOutputEventHandlerandStandardErrorEventHandlerToString()call inIsAvailable- process has already exited, no more events will fireOriginal prompt
This section details on the original issue you should resolve
<issue_title>Assertion failed: minBlockCharCount > 0</issue_title>
<issue_description>Failed in: runtime-coreclr pgo 20260205.1
Failed tests:
Error message:
Stack trace: